package com.yidu.t299.dao.chr;

import com.yidu.t299.domain.chr.Lesson;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

@Mapper
public interface LessonMapper {

    /**
     * 根据主键查询课程信息
     * @param lessonId 主键
     * @return 课程信息
     */
    @Select({
        "select",
        " lesson_id, lesson_name, period_times, lesson_times, speciality_id, stock_id",
        " from lesson",
        " where lesson_id = #{lessonId,jdbcType=INTEGER}"
    })
    @Results(id = "LessonMap",value = {
        @Result(column="lesson_id", property="lessonId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="lesson_name", property="lessonName", jdbcType=JdbcType.VARCHAR),
        @Result(column="period_times", property="periodTimes", jdbcType=JdbcType.INTEGER),
        @Result(column="lesson_times", property="lessonTimes", jdbcType=JdbcType.INTEGER),
        @Result(column="speciality_id", property="specialityId", jdbcType=JdbcType.INTEGER),
        @Result(column="stock_id", property="stockId", jdbcType=JdbcType.INTEGER)
    })
    Lesson selectByPrimaryKey(Integer lessonId);

    /**
     * 根据课程名称查询课程编号
     * @param lessonName 课程名称
     * @return 课程编号
     */
    @Select({
            "select lesson_id from lesson",
            " where lesson_name = #{lessonName,jdbcType=VARCHAR}"
    })
    String selectByName(String lessonName);

    /**
     * 查询所有课程信息
     * @return 课程名称
     */
    @Select({
            "select * from lesson"
    })
    @ResultMap("LessonMap")
    List<Lesson> selectAll();

}